package dao;

import entity.Article;
import util.BaseDao;
import util.DButils;

import java.sql.Connection;
import java.sql.PreparedStatement;


public class ArticleDao extends BaseDao<Article> {
    public Article getByUserName(String userName) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        Article article = null;
        try {
//            connection = DButils.getConnection();
//            StringBuilder sb = new StringBuilder("SELECT  id,name,email,user_name,password");
//            sb.append(" FROM " +User.class.getSimpleName().toLowerCase());
//            sb.append(" WHERE user_name=?");
//            String sql = sb.toString();
//            System.out.println(sql);
//            preparedStatement = connection.prepareStatement(sql);
//            preparedStatement.setObject(1, userName);
//            System.out.println("params ==>"+userName);
//            ResultSet resultSet = preparedStatement.executeQuery();
//            int index = 0;
//            if (resultSet.next()) {
//                user1 = new User();
//                user1.setId((int)resultSet.getObject(1));
//                user1.setName(resultSet.getObject(2).toString());
//                user1.setEmail(resultSet.getObject(3).toString());
//                user1.setUserName(resultSet.getObject(4).toString());
//                user1.setPassword(resultSet.getObject(5).toString());
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DButils.close(connection,preparedStatement);
            return article;
        }
    }
}
